package com.zl.quickdoc.resolver.converter.impl;

import java.util.List;

import com.github.javaparser.ast.CompilationUnit;
import com.zl.quickdoc.model.ApiField;
import com.zl.quickdoc.resolver.JavaSourceFileFactory;
import com.zl.quickdoc.resolver.converter.AbstractJavaDocTag;
import com.zl.quickdoc.resolver.converter.JavaParserTagConverter;
import com.zl.quickdoc.utils.ParserJavaUtils;

/**
 * 针对@paramObj和@see的转换器
 *
 * @author zhouliang
 *
 */
public class ParamObjTagConverter implements JavaParserTagConverter {
    
    @SuppressWarnings("unchecked")
    @Override
    public AbstractJavaDocTag<ApiField> converter(String comments) {
        DefaultStringParserTagConverterImpl stringtag = new DefaultStringParserTagConverterImpl();
        AbstractJavaDocTag<String> docTag = stringtag.converter(comments);
        JavaSourceFileFactory ist = JavaSourceFileFactory.getInstance();
        CompilationUnit cu = ist.getJavaUnit(docTag.getValues());
        if (cu == null) {
            System.out.println("不存在源文件: " + docTag.getValues());
            return null;
        }
        List<CompilationUnit> flist = ist.getSelfFatherClass(comments);
        ApiField field = ParserJavaUtils.analysisApiField(flist, ist, null);
        return new ParamObjTagImpl(docTag.getTagName(), field);
    }


    /**
     * 针对@see注释标签进行封装,返回@see上注释的类信息
     * <p>
     * @author zhouliang
     */
    public class ParamObjTagImpl extends AbstractJavaDocTag<ApiField> {
        private ApiField field;

        public ParamObjTagImpl(String tagName, ApiField field) {
            super(tagName);
            this.field = field;
        }

        @Override
        public ApiField getValues() {
            return field;
        }
    }
}
